package com.yhy.shiro.test2.permission;

import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.permission.PermissionResolver;
import org.apache.shiro.authz.permission.WildcardPermission;


/**
 * BitAndWildPermissionResolver实现了PermissionResolver接口，
 * 并根据权限字符串是否以“+”开头来解析权限字符串为BitPermission或WildcardPermission。
 * @author yhy
 *
 */
public class BitAndWildPermissionResolver implements PermissionResolver {

	@Override
	public Permission resolvePermission(String permissionString) {
		System.out.print("解析权限字符串: " + permissionString + " ");
		if ( permissionString.startsWith("+") ){
			System.out.println("使用 BitPermission 鉴权");
			return new BitPermission(permissionString);
		}else {
			System.out.println("使用 WildcardPermission 鉴权");
			return new WildcardPermission(permissionString);
		}
	}

}
